﻿using System.Configuration.Install;
using System.ServiceProcess;

namespace SBWindowsService
{
    /// <summary>
    /// Serves as a base class for the Windows Service installer.
    /// </summary>
    public class WindowsServiceInstaller : Installer
    {
        /// <summary>
        /// Service process installer.
        /// </summary>
        private readonly ServiceProcessInstaller serviceProcessInstaller;

        /// <summary>
        /// Service installer.
        /// </summary>
        private readonly ServiceInstaller serviceInstaller;

        /// <summary>
        /// Initializes a new instance of the <see cref="WindowsServiceInstaller"/> class.
        /// </summary>
        /// <param name="name">The name of service.</param>
        public WindowsServiceInstaller(string name)
        {
            serviceProcessInstaller = new ServiceProcessInstaller
            {
                Account = ServiceAccount.LocalSystem,
                Password = null,
                Username = null,
            };

            serviceInstaller = new ServiceInstaller
            {
                DisplayName = name,
                ServiceName = name,
                StartType = ServiceStartMode.Automatic
            };

            Installers.AddRange(new Installer[] 
            {
                serviceProcessInstaller,
                serviceInstaller
            });
        }
    }
}
